// 树形分类数据
export const categoryTree = [
  {
    id: 1,
    name: '手机',
    children: [
      { id: 101, name: '5G手机' },
      { id: 102, name: '苹果手机' },
      { id: 103, name: '游戏手机' },
      { id: 104, name: '拍照手机' },
      { id: 105, name: '折叠屏手机' },
      { id: 106, name: '老人机' },
      { id: 107, name: '骁龙手机' },
    ],
  },
  {
    id: 2,
    name: '电脑办公',
    children: [
      { id: 201, name: '笔记本' },
      { id: 202, name: '游戏本' },
      { id: 203, name: '轻薄本' },
    ],
  },
  {
    id: 3,
    name: '家电',
    children: [
      { id: 301, name: '空调' },
      { id: 302, name: '冰箱' },
      { id: 303, name: '洗衣机' },
      { id: 304, name: '电视' },
      { id: 305, name: '热水器' },
      { id: 306, name: '电风扇' },
    ],
  },
  {
    id: 4,
    name: '家居生活',
    children: [
      { id: 401, name: '生活家电' },
      { id: 402, name: '厨卫大电' },
      { id: 403, name: '家装建材' },
    ],
  },
  {
    id: 5,
    name: '食品酒饮',
    children: [
      { id: 501, name: '奶粉' },
      { id: 502, name: '白酒' },
      { id: 503, name: '牛奶' },
    ],
  },
  {
    id: 6,
    name: '母婴用品',
    children: [{ id: 601, name: '纸尿裤' }],
  },
  {
    id: 7,
    name: '个护清洁',
    children: [
      { id: 701, name: '抽纸' },
      { id: 702, name: '护肤套装' },
    ],
  },
  {
    id: 8,
    name: '特色专区',
    children: [
      { id: 801, name: '大汇聚' },
      { id: 802, name: '百亿补贴' },
      { id: 803, name: '好物天天抢' },
    ],
  },
]

// 根据分类ID获取分类信息
export const getCategoryById = (id, categories = categoryTree) => {
  for (const category of categories) {
    if (category.id === id) {
      return category
    }
    if (category.children) {
      const found = getCategoryById(id, category.children)
      if (found) {
        return found
      }
    }
  }
  return null
}

// 获取所有二级分类
export const getAllSubCategories = () => {
  const subCategories = []
  categoryTree.forEach(category => {
    if (category.children) {
      subCategories.push(...category.children)
    }
  })
  return subCategories
}
